﻿using Gargoyle.Roton;

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace Gargoyle.ZZT
{
    abstract partial class DisplayCommon : Display
    {
        protected enum SelectionType
        {
            LongTextInput,
            Range,
            RangeBinary,
            RangeDirection,
            Scroll,
            TextInput,
            YesNo
        }

        // state
        protected bool busy;
        protected Game game;
        protected Info info;
        protected Video inputVideo;
        protected Video outputVideo;

        // return values
        protected ByteString longTextInputValue;
        protected int rangeValue;
        protected int scrollLine;
        protected ByteString textInputValue;
        protected int yesNoValue;

        public DisplayCommon(Game g, Video input)
        {
            game = g;
            info = g.Info;
            inputVideo = input;
            outputVideo = g.Video;
        }

        public bool Busy
        {
            get { return busy; }
        }

        abstract public void DrawMessage(ByteString message, int color)
        {
        }

        abstract public void EraseMessage()
        {
        }

        abstract public void FadeIn()
        {
        }

        abstract public void FadeOut()
        {
        }

        protected Point[] GenerateFade(Size size)
        {
            Random rand = new Random();
            Point[] result = new Point[size.Width * size.Height];
            int index = 0;

            for (int y = 0; y < size.Height; y++)
                for (int x = 0; x < size.Width; x++)
                    result[index++] = new Point(x, y);

            int iterations = result.Length;
            for (int i = 0; i < iterations; i++)
            {
                int j = rand.Next(iterations);
                int k = rand.Next(iterations);
                Point point = result[j];
                result[j] = result[k];
                result[k] = point;
            }

            return result;
        }

        abstract public void LongTextInput()
        {
        }

        public ByteString LongTextInputValue
        {
            get { return longTextInputValue; }
        }

        abstract public void Range(ByteString text)
        {
        }

        abstract public void RangeBinary(ByteString text)
        {
        }

        abstract public void RangeDirection(ByteString text)
        {
        }

        public int RangeValue
        {
            get { return rangeValue; }
        }

        abstract public void RedrawBoard()
        {
        }

        abstract public void RedrawHudEditor()
        {
        }

        abstract public void RedrawHudGame()
        {
        }

        abstract public void RedrawHudTitle()
        {
        }

        abstract public void Scroll(ByteString title, ByteString data)
        {
        }

        public int ScrollLine
        {
            get { return scrollLine; }
        }

        abstract public void TextInput()
        {
        }

        public ByteString TextInputValue
        {
            get { return textInputValue; }
        }

        abstract public void UpdateBoard(Location location)
        {
        }

        abstract public void UpdateHudEditor()
        {
        }

        abstract public void UpdateHudGame()
        {
        }

        abstract public void UpdateHudTitle()
        {
        }

        abstract public void YesNo()
        {
        }

        public int YesNoValue
        {
            get { return yesNoValue; }
        }
    }
}
